<%
'******************************************************************************************
'分页类pager
'本类中共提供4种风格，第4个风格中共提供6种皮肤风格
'使用范例：
'set pageObj=new pager
'默认第一种风格，如果需要指定某种风格使用：pageObj.pageskin=1 '如果需要跟换风格只需更改数字，范围1-9
'response.Write pageObj.link(rs.recordcount,rs.pagesize,page,"?page=",qryString)
'Publisher:WangJinkun.Date:2011-06-01 
'Copyright (C) evil_god@163.com (http://blog.163.com/evil_god).All rights reserved.
'******************************************************************************************
class pager
	public total,pageSizes,pages,curPage,offset,perNum,text,img_path
	public pageskin,lang_PageTotal,lang_Page,lang_PageLocation,lang_PageHome,lang_PageEnd,lang_PagePre,lang_PageNext,lang_PageGo,lang_Total,lang_Pagenum,lang_PageTenPre,lang_PageTenNext
	Public Sub Class_Initialize() '类的初始化.通常,可以在这设置一些默认值
		total=0
		pageSizes=0
		perNum=10
		pageskin=1
		lang_PageTotal="共"
		lang_Page="页"
		lang_PageLocation="当前第"
		lang_PageHome="首页"
		lang_PageEnd="末页"
		lang_PagePre="上一页"
		lang_PageNext="下一页"
		lang_PageGo="转至第"
		lang_Total="条记录"
		lang_Pagenum="页次"
		text=""
		img_path="image/"
	End Sub 
    function pagerFun()
		pages = ceil(total/pageSizes)
		pagerFun=pages
    end function
    function curPageFun(curPageNum)
   	    curPageNum=clng(curPageNum)
		if curPageNum>0 then
			curPage=curPageNum
		else
			curPage=1
		end if
        curPageFun=curPage
    end function
	function offsetFun()
		offset=pageSizes*(curPage-1)
		offsetFun=offset
	end function
	public function link(ByVal totalNum, ByVal pageSizesNum, ByVal curPageNum, ByVal url, ByVal exc)
		total=totalNum
		pageSizes=pageSizesNum
		curPageFun(curPageNum)
		pagerFun()
		offsetFun()
		if pageskin="" or pageskin=0 or pageskin>9 then pageskin=1
		select case pageskin
			case 1
			call linkStyle1(url,exc)
			case 2
			call linkStyle2(url,exc)
			case 3
			call linkStyle3(url,exc)
			case 4,5,6,7,8,9
			call linkStyle4(url,exc)
		end select
        link=text 
     end function
	 sub linkStyle1(url,exc)
		text= ""&lang_PageTotal&"<span>"&total&"</span>"&lang_Total&" "&lang_PageLocation&"<span>"&curPage&"</span>/"&pages&lang_Pagenum&" "
		if curPage = 1 and pages>1 then 
			text=text& ""&lang_PageHome&" "&lang_PagePre&" <a href="&url&(curPage+1)&exc&">"&lang_PageNext&"</a>  <a href="&url&pages&exc&">"&lang_PageEnd&"</a>"
		elseif curPage=pages and pages>1 then
			text=text& "<a href="&url&"1"&exc&">"&lang_PageHome&"</a> <a href="&url&(curPage-1)&exc&">"&lang_PagePre&"</a> "&lang_PageNext&" "&lang_PageEnd&""
		elseif curPage>1 and curPage<=pages then
			text=text& "<a href="&url&"1"&exc&">"&lang_PageHome&"</a> <a href="&url&(curPage-1)&exc&">"&lang_PagePre&"</a> <a href="&url&(curPage+1)&exc&">"&lang_PageNext&"</a>  <a href="&url&pages&exc&">"&lang_PageEnd&"</a>"
		end if
		text=text&" "&lang_PageGo&" <select onchange='javascript:window.location.href=this.options[this.selectedIndex].value'>"
		for i=1 to pages
		   if i=curPage then
		   		text=text&"<option selected='selected' value='"&url&i&exc&"' >"&i&"</option>"
		   else
		  		text=text&"<option value='"&url&i&exc&"' >"&i&"</option>"
		   end if
		next
		text=text&"</select> "&lang_Page&" "
	 end sub
	 sub linkStyle2(url,exc)
		text=""
		if curPage=1 and pages>1 then
			text=text&lang_PageHome&" "&lang_PagePre&" <a href="&url&(curPage+1)&exc&">"&lang_PageNext&"</a>  <a href="&url&pages&exc&">"&lang_PageEnd&"</a>"
		elseif curPage=pages and pages>1 then
			text=text&"<a href="&url&"1"&exc&">"&lang_PageHome&"</a> <a href="&url&(curPage-1)&exc&">"&lang_PagePre&"</a> "&lang_PageNext&" "&lang_PageEnd&""
		elseif curPage>1 and curPage<=pages then
			text=text&"<a href="&url&"1"&exc&">"&lang_PageHome&"</a> <a href="&url&(curPage-1)&exc&">"&lang_PagePre&"</a> <a href="&url&(curPage+1)&exc&">"&lang_PageNext&"</a>  <a href="&url&pages&exc&">"&lang_PageEnd&"</a>"
		end if
			text=text&"&nbsp;&nbsp;"&lang_PageTotal&"<span>"&total&"</span>"&lang_Total&" "&lang_PageLocation&"<span>"&curPage&"</span>/"&pages&lang_Pagenum
	 end sub
	 sub linkStyle3(url,exc)
		text=""
		if curPage=1 then
			text=text&"<a style='font-family: Tahoma, Verdana;' href="&url&"1"&exc&" title='"&lang_PageHome&"'><b>«</b></a> <a style='font-size:12px;font-family: Tahoma, Verdana;' href="&url&"1"&exc&" title='"&lang_PagePre&"'>‹</a>"
		else
			text=text&"<a style='font-family: Tahoma, Verdana;' href="&url&"1"&exc&" title='"&lang_PageHome&"'><b>«</b></a> <a style='font-family: Tahoma, Verdana;' href="&url&(curPage-1)&exc&" title='"&lang_PagePre&"'>‹</a>"
		end if
		if pages>10 then
			if curPage>5 then
				if pages-curPage>5 then
					startnum=curPage-4
					endnum=curPage+5
				else
					startnum=pages-9
					endnum=pages
				end if
			else
				startnum=1
				endnum=10
			end if
		else
			startnum=1
			endnum=pages
		end if
		for i=startnum to endnum
			if i=curPage then page_stylenow="style='font-weight:bold;'"
			text=text&" <a "&page_stylenow&" href="&url&i&exc&">["&i&"]</a> "
			page_stylenow=""
		next
		if curPage=pages then
			text=text&"<a style='font-family: Tahoma, Verdana;' href="&url&pages&exc&" title='"&lang_PageNext&"'>›</a> <a style='font-family: Tahoma, Verdana;' href="&url&pages&exc&" title='"&lang_PageEnd&"'><b>»</b></a>"
		else
			text=text&"<a style='font-family: Tahoma, Verdana;' href="&url&(curPage+1)&exc&" title='"&lang_PageNext&"'>›</a> <a style='font-family: Tahoma, Verdana;'  href="&url&pages&exc&" title='"&lang_PageEnd&"'><b>»</b></a>"
		end if
	 end sub
	 sub linkStyle4(url,exc)
		lang_PageTenPre="上"&perNum&"页"
		lang_PageTenNext="下"&perNum&"页"
		text=""
		select case pageskin
			case 4
				text=text&"<style>"
				text=text&".digg4 { padding:3px; margin:3px; text-align:center; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;}"
				text=text&".digg4 a { border:1px solid #aaaadd; padding:2px 5px 2px 5px; margin:2px; color:#000099; text-decoration:none;}"
				text=text&".digg4 a:hover { border:1px solid #000099; color:#000000;}"
				text=text&".digg4 a:active {border:1px solid #000099; color:#000000;}"
				text=text&".digg4 span.current { border:1px solid #000099; background-color:#000099; padding:2px 5px 2px 5px; margin:2px; color:#FFFFFF; text-decoration:none;}"
				text=text&".digg4 span.disabled { border:1px solid #eee; padding:2px 5px 2px 5px; margin:2px; color:#ddd;}"
				text=text&"</style>"
			case 5
				text=text&"<style>"
				text=text&".digg4 { padding:3px; margin:3px; text-align:center; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;}"
				text=text&".digg4  a { border:1px solid #ccdbe4; padding:2px 8px 2px 8px; background-position:50%; margin:2px; color:#0061de; text-decoration:none;}"
				text=text&".digg4  a:hover { border:1px solid #2b55af; color:#fff; background-color:#3666d4;}"
				text=text&".digg4  a:active {border:1px solid #000099; color:#000000;}"
				text=text&".digg4  span.current { padding:2px 8px 2px 8px; margin:2px; color:#000; text-decoration:none;}"
				text=text&".digg4  span.disabled { border:1px solid #ccdbe4; padding:2px 8px 2px 8px; margin:2px; color:#ddd;}"
				text=text&" </style>"
			case 6
				text=text&"<style>"
				text=text&".digg4 { padding:3px; color:#ff6500; margin:3px; text-align:center; font-family: Tahoma, Arial, Helvetica, Sans-serif; font-size: 12px;}"
				text=text&".digg4 a { border:1px solid  #ff9600; padding:2px 7px 2px 7px; background-position:50% bottom; margin:2px; color:#ff6500; background-image:url("&img_path&"page6.jpg); text-decoration:none;}"
				text=text&".digg4 a:hover { border:1px solid #ff9600; color:#ff6500; background-color:#ffc794;}"
				text=text&".digg4 a:active {border:1px solid #ff9600; color:#ff6500; background-color:#ffc794;}"
				text=text&".digg4 span.current {border:1px solid #ff6500; padding:2px 7px 2px 7px; margin:2px; color:#ff6500; background-color:#ffbe94; text-decoration:none;}"
				text=text&".digg4 span.disabled { border:1px solid #ffe3c6; padding:2px 7px 2px 7px; margin:2px; color:#ffe3c6;}"
				text=text&" </style>"  
			case 7
				text=text&"<style>"
				text=text&".digg4  { padding:3px; margin:3px; text-align:center; font-family: Tahoma, Arial, Helvetica, Sans-serif, sans-serif; font-size: 12px;}"
				text=text&".digg4  a { border:1px solid  #2c2c2c; padding:2px 5px 2px 5px; background:url("&img_path&"page7.gif) #2c2c2c; margin:2px; color:#fff; text-decoration:none;}"
				text=text&".digg4  a:hover { border:1px solid #aad83e; color:#fff;background:url("&img_path&"page7_2.gif) #aad83e;}"
				text=text&".digg4  a:active { border:1px solid #aad83e; color:#fff;background:url("&img_path&"page7_2.gif) #aad83e;}"
				text=text&".digg4  span.current {border:1px solid #aad83e; padding:2px 5px 2px 5px; margin:2px; color:#fff;background:url("&img_path&"page7_2.gif) #aad83e; text-decoration:none;}"
				text=text&".digg4  span.disabled { border:1px solid #f3f3f3; padding:2px 5px 2px 5px; margin:2px; color:#ccc;}"
				text=text&" </style>" 
			case 8
				text=text&"<style>"
				text=text&".digg4  { padding:3px; margin:3px; text-align:center; font-family:Tahoma, Arial, Helvetica, Sans-serif;  font-size: 12px;}"
				text=text&".digg4  a { border:1px solid #ddd; padding:2px 5px 2px 5px; margin:2px; color:#aaa; text-decoration:none;}"
				text=text&".digg4  a:hover { border:1px solid #a0a0a0; }"
				text=text&".digg4  a:hover { border:1px solid #a0a0a0; }"
				text=text&".digg4  span.current {border:1px solid #e0e0e0; padding:2px 5px 2px 5px; margin:2px; color:#aaa; background-color:#f0f0f0; text-decoration:none;}"
				text=text&".digg4  span.disabled { border:1px solid #f3f3f3; padding:2px 5px 2px 5px; margin:2px; color:#ccc;}"
				text=text&" </style>"
			case 9
				text=text&"<style>"
				text=text&".digg4 { padding:3px; margin:3px; text-align:center; font-family:Tahoma, Arial, Helvetica, Sans-serif;  font-size: 12px;}"
				text=text&".digg4  a { border:1px solid #ddd; padding:2px 5px 2px 5px; margin:2px; color:#88af3f; text-decoration:none;}"
				text=text&".digg4  a:hover { border:1px solid #85bd1e; color:#638425; background-color:#f1ffd6; }"
				text=text&".digg4  a:hover { border:1px solid #85bd1e; color:#638425; background-color:#f1ffd6; }"
				text=text&".digg4  span.current {border:1px solid #b2e05d; padding:2px 5px 2px 5px; margin:2px; color:#fff; background-color:#b2e05d; text-decoration:none;}"
				text=text&".digg4  span.disabled { border:1px solid #f3f3f3; padding:2px 5px 2px 5px; margin:2px; color:#ccc;}"
				text=text&" </style>"
		end select
		if pages>perNum+2 then
			startnum=floor(curPage/perNum)*perNum+1
			if floor(curPage/perNum)=curPage/perNum then startnum=floor(curPage/perNum)*perNum+1-perNum
			if pages-startnum>perNum+2 then
				if startnum<>1 then
					endnum=startnum+perNum-1
					middletext="..."
					prepagenow="<a href='"&url&(startnum-1)&exc&"' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenPre&"'>‹</a>"
					nextpagenow="<a href='"&url&(startnum+perNum)&exc&"' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenNext&"'>›</a>"
				else
					endnum=startnum+perNum-1
					middletext="..."
					prepagenow="<span class='disabled' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenPre&"'>‹</span>"
					nextpagenow="<a href='"&url&(startnum+perNum)&exc&"' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenNext&"'>›</a>"
				end if
			else
				prepagenow="<a href='"&url&(startnum-1)&exc&"' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenPre&"'>‹</a>"
				nextpagenow="<span class='disabled' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenNext&"'>›</span>"
				endnum=pages-2
				middletext=""
			end if
		else
			startnum=1
			endnum=pages-2
			middletext=""
			prepagenow="<span class='disabled' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenPre&"'>‹</span>"
			nextpagenow="<span class='disabled' style='font-family: Tahoma, Verdana;' title='"&lang_PageTenNext&"'>›</span>"
		end if
		text=text&"<div class='digg4'>"
		if curPage=1 then
			text=text&"<span class='disabled' style='font-family: Tahoma, Verdana;' title='"&lang_PageHome&"'><b>«</b></span>"&prepagenow
		else
			text=text&"<a style='font-family: Tahoma, Verdana;' href="&url&"1"&exc&" title='"&lang_PageHome&"'><b>«</b></a>"&prepagenow
		end if
		for i=startnum to endnum
			if i=curPage then
				text=text&"<span class='current'>"&i&"</span>"
			else
				text=text&" <a href="&url&i&exc&">"&i&"</a> "
			end if
		next
		text=text&middletext
		if pages>1 then
			if pages-1=curPage then
				text=text&"<span class='current'>"&(pages-1)&"</span>"
			else
				text=text&" <a href="&url&(pages-1)&exc&">"&(pages-1)&"</a> "
			end if
		end if
		if pages=curPage then
			text=text&"<span class='current'>"&pages&"</span>"
		else
			text=text&" <a href="&url&pages&exc&">"&pages&"</a> "
		end if
		if curPage=pages then
			text=text&nextpagenow&"<span class='disabled' style='font-family: Tahoma, Verdana;' title='"&lang_PageEnd&"'><b>»</b></span>"
		else
			text=text&nextpagenow&"<a style='font-family: Tahoma, Verdana;' href="&url&pages&exc&" title='"&lang_PageEnd&"'><b>»</b></a>"
		end if
		text=text&"</div>"
	 end sub
end class
'******************************************************************************************
'Copyright (C) evil_god@163.com (http://blog.163.com/evil_god).All rights reserved.
'******************************************************************************************
%>